package br.ufba.lasid.jitclouds.mda.vo;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.BitSet;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;

import org.apache.thrift.TBase;
import org.apache.thrift.TBaseHelper;
import org.apache.thrift.TException;
import org.apache.thrift.TFieldRequirementType;
import org.apache.thrift.meta_data.FieldMetaData;
import org.apache.thrift.meta_data.FieldValueMetaData;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolUtil;
import org.apache.thrift.protocol.TStruct;
import org.apache.thrift.protocol.TType;
import org.apache.thrift.transport.TIOStreamTransport;

public class MDA implements TBase<MDA, MDAFields>, Serializable, Cloneable {

    private static final long serialVersionUID = 254295723980764547L;
    private static final TStruct STRUCT_DESC = new TStruct("Item");
    private static final TField ID_FIELD_DESC = new TField("id",
            TType.STRING, (short) 1);
    private static final TField IP_FIELD_DESC = new TField("ip",
            TType.STRING, (short) 2);
    private static final TField CREATION_TIME_FIELD_DESC = new TField(
            "creationTime", TType.I64, (short) 3);
    private static final TField ID_MACHINE_FIELD_DESC = new TField("ID_MACHINE",
            TType.STRING, (short) 4);
    private static final TField STATUS_FIELD_DESC = new TField("STATUS",
            TType.STRING, (short) 5);
    private static final TField QUEUE_NAME_FIELD_DESC = new TField("queueName",
            TType.STRING, (short) 6);
    private String id;
    private String ip;
    private long creationTime;
    private String idMachine;
    private String status;
    private String queueName;
    // isset id assignments
    private static final int __CREATIONTIME_ISSET_ID = 0;
    private BitSet __isset_bit_vector = new BitSet(1);
    public static final Map<MDAFields, FieldMetaData> metaDataMap;

    static {
        Map<MDAFields, FieldMetaData> tmpMap = new EnumMap<MDAFields, FieldMetaData>(
                MDAFields.class);
        tmpMap.put(MDAFields.ID,
                new FieldMetaData(MDAFields.ID.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.STRING)));
        tmpMap.put(MDAFields.IP, new FieldMetaData(MDAFields.IP.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.STRING)));
        tmpMap.put(MDAFields.CREATION_TIME,
                new FieldMetaData(MDAFields.CREATION_TIME.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.I64)));
        tmpMap.put(MDAFields.ID_MACHINE,
                new FieldMetaData(MDAFields.ID_MACHINE.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.STRING)));
        tmpMap.put(MDAFields.STATUS,
                new FieldMetaData(MDAFields.STATUS.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.STRING)));
        tmpMap.put(MDAFields.QUEUE_NAME,
                new FieldMetaData(MDAFields.QUEUE_NAME.getFieldName(),
                TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                TType.STRING)));
        metaDataMap = Collections.unmodifiableMap(tmpMap);
        FieldMetaData.addStructMetaDataMap(MDA.class, metaDataMap);
    }

    public MDA() {
    }

    public MDA(String id, String ip, long creationTime, String idMachine,
            String status, String queueName) {
        this();
        this.id = id;
        this.ip = ip;
        this.creationTime = creationTime;
        setCreationTimeIsSet(true);
        this.idMachine = idMachine;
        this.status = status;
        this.queueName = queueName;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public MDA(MDA other) {
        __isset_bit_vector.clear();
        __isset_bit_vector.or(other.__isset_bit_vector);
        if (other.isSetID()) {
            this.id = other.id;
        }
        if (other.isSetIP()) {
            this.ip = other.ip;
        }
        this.creationTime = other.creationTime;
        if (other.isSetIdMachine()) {
            this.idMachine = other.idMachine;
        }
        if (other.isSetStatus()) {
            this.status = other.status;
        }
        if (other.isSetQueueName()) {
            this.queueName = other.queueName;
        }
    }

    @Override
    public MDA deepCopy() {
        return new MDA(this);
    }

    @Override
    public void clear() {
        this.id = null;
        this.ip = null;
        setCreationTimeIsSet(false);
        this.creationTime = 0;
        this.idMachine = null;
        this.status = null;
        this.queueName = null;
    }

    public String getID() {
        return this.id;
    }

    public MDA setID(String id) {
        this.id = id;
        return this;
    }

    public void unsetID() {
        this.id = null;
    }

    /**
     * Returns true if field id is set (has been assigned a value) and false
     * otherwise
     */
    public boolean isSetID() {
        return this.id != null;
    }

    public void setIDIsSet(boolean value) {
        if (!value) {
            this.id = null;
        }
    }

    public String getIP() {
        return this.ip;
    }

    public MDA setIP(String ip) {
        this.ip = ip;
        return this;
    }

    public void unsetIP() {
        this.ip = null;
    }

    /**
     * Returns true if field data is set (has been assigned a value) and false
     * otherwise
     */
    public boolean isSetIP() {
        return this.ip != null;
    }

    public void setIPIsSet(boolean value) {
        if (!value) {
            this.ip = null;
        }
    }

    public long getCreationTime() {
        return this.creationTime;
    }

    public MDA setCreationTime(long creationTime) {
        this.creationTime = creationTime;
        setCreationTimeIsSet(true);
        return this;
    }

    public void unsetCreationTime() {
        __isset_bit_vector.clear(__CREATIONTIME_ISSET_ID);
    }

    /**
     * Returns true if field creationTime is set (has been assigned a value) and
     * false otherwise
     */
    public boolean isSetCreationTime() {
        return __isset_bit_vector.get(__CREATIONTIME_ISSET_ID);
    }

    public void setCreationTimeIsSet(boolean value) {
        __isset_bit_vector.set(__CREATIONTIME_ISSET_ID, value);
    }

    public String getIdMachine() {
        return this.idMachine;
    }

    public MDA setIdMachine(String idMachine) {
        this.idMachine = idMachine;
        return this;
    }

    public void unsetIdMachine() {
        this.idMachine = null;
    }

    /**
     * Returns true if field metadata is set (has been assigned a value) and
     * false otherwise
     */
    public boolean isSetIdMachine() {
        return this.idMachine != null;
    }

    public void setIdMachineIsSet(boolean value) {
        if (!value) {
            this.idMachine = null;
        }
    }

    public String getStatus() {
        return this.status;
    }

    public MDA setStatus(String status) {
        this.status = status;
        return this;
    }

    public void unsetStatus() {
        this.status = null;
    }

    /**
     * Returns true if field status is set (has been assigned a value) and false
     * otherwise
     */
    public boolean isSetStatus() {
        return this.status != null;
    }

    public void setStatusIsSet(boolean value) {
        if (!value) {
            this.status = null;
        }
    }

    public String getQueueName() {
        return this.queueName;
    }

    public MDA setQueueName(String queueName) {
        this.queueName = queueName;
        return this;
    }

    public void unsetQueueName() {
        this.queueName = null;
    }

    /**
     * Returns true if field queueName is set (has been assigned a value) and
     * false otherwise
     */
    public boolean isSetQueueName() {
        return this.queueName != null;
    }

    public void setQueueNameIsSet(boolean value) {
        if (!value) {
            this.queueName = null;
        }
    }

    public void setFieldValue(MDAFields field, Object value) {
        switch (field) {
            case ID:
                if (value == null) {
                    unsetID();
                } else {
                    setID((String) value);
                }
                break;

            case IP:
                if (value == null) {
                    unsetIP();
                } else {
                    setIP((String) value);
                }
                break;

            case CREATION_TIME:
                if (value == null) {
                    unsetCreationTime();
                } else {
                    setCreationTime((Long) value);
                }
                break;

            case ID_MACHINE:
                if (value == null) {
                    unsetIdMachine();
                } else {
                    setIdMachine((String) value);
                }
                break;

            case STATUS:
                if (value == null) {
                    unsetStatus();
                } else {
                    setStatus((String) value);
                }
                break;

            case QUEUE_NAME:
                if (value == null) {
                    unsetQueueName();
                } else {
                    setQueueName((String) value);
                }
                break;

        }
    }

    public Object getFieldValue(MDAFields field) {
        switch (field) {
            case ID:
                return getID();

            case IP:
                return getIP();

            case CREATION_TIME:
                return new Long(getCreationTime());

            case ID_MACHINE:
                return getIdMachine();

            case STATUS:
                return getStatus();

            case QUEUE_NAME:
                return getQueueName();
        }
        throw new IllegalStateException();
    }

    /**
     * Returns true if field corresponding to fieldID is set (has been assigned
     * a value) and false otherwise
     */
    public boolean isSet(MDAFields field) {
        if (field == null) {
            throw new IllegalArgumentException();
        }

        switch (field) {
            case ID:
                return isSetID();
            case IP:
                return isSetIP();
            case CREATION_TIME:
                return isSetCreationTime();
            case ID_MACHINE:
                return isSetIdMachine();
            case STATUS:
                return isSetStatus();
            case QUEUE_NAME:
                return isSetQueueName();
        }
        throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
        if (that == null) {
            return false;
        }
        if (that instanceof MDA) {
            return this.equals((MDA) that);
        }
        return false;
    }

    public boolean equals(MDA that) {
        if (that == null) {
            return false;
        }

        boolean this_present_id = true && this.isSetID();
        boolean that_present_id = true && that.isSetID();
        if (this_present_id || that_present_id) {
            if (!(this_present_id && that_present_id)) {
                return false;
            }
            if (!this.id.equals(that.id)) {
                return false;
            }
        }

        boolean this_present_ip = true && this.isSetIP();
        boolean that_present_ip = true && that.isSetIP();
        if (this_present_ip || that_present_ip) {
            if (!(this_present_ip && that_present_ip)) {
                return false;
            }
            if (!this.ip.equals(that.ip)) {
                return false;
            }
        }

        boolean this_present_creationTime = true;
        boolean that_present_creationTime = true;
        if (this_present_creationTime || that_present_creationTime) {
            if (!(this_present_creationTime && that_present_creationTime)) {
                return false;
            }
            if (this.creationTime != that.creationTime) {
                return false;
            }
        }

        boolean this_present_id_machine = true && this.isSetIdMachine();
        boolean that_present_id_machine = true && that.isSetIdMachine();
        if (this_present_id_machine || that_present_id_machine) {
            if (!(this_present_id_machine && that_present_id_machine)) {
                return false;
            }
            if (!this.idMachine.equals(that.idMachine)) {
                return false;
            }
        }

        boolean this_present_status = true && this.isSetStatus();
        boolean that_present_status = true && that.isSetStatus();
        if (this_present_status || that_present_status) {
            if (!(this_present_status && that_present_status)) {
                return false;
            }
            if (!this.status.equals(that.status)) {
                return false;
            }
        }

        boolean this_present_queueName = true && this.isSetQueueName();
        boolean that_present_queueName = true && that.isSetQueueName();
        if (this_present_queueName || that_present_queueName) {
            if (!(this_present_queueName && that_present_queueName)) {
                return false;
            }
            if (!this.queueName.equals(that.queueName)) {
                return false;
            }
        }

        return true;
    }

    @Override
    public int hashCode() {
        return 0;
    }

    @Override
    public int compareTo(MDA other) {
        if (!getClass().equals(other.getClass())) {
            return getClass().getName().compareTo(other.getClass().getName());
        }

        int lastComparison = 0;
        MDA typedOther = (MDA) other;

        lastComparison = Boolean.valueOf(isSetID()).compareTo(
                typedOther.isSetID());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetID()) {
            lastComparison = TBaseHelper.compareTo(this.id,
                    typedOther.id);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetIP()).compareTo(
                typedOther.isSetIP());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetIP()) {
            lastComparison = TBaseHelper.compareTo(this.ip, typedOther.ip);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetCreationTime()).compareTo(
                typedOther.isSetCreationTime());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetCreationTime()) {
            lastComparison = TBaseHelper.compareTo(this.creationTime,
                    typedOther.creationTime);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetIdMachine()).compareTo(
                typedOther.isSetIdMachine());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetIdMachine()) {
            lastComparison = TBaseHelper.compareTo(this.idMachine,
                    typedOther.idMachine);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetStatus()).compareTo(
                typedOther.isSetStatus());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetStatus()) {
            lastComparison = TBaseHelper.compareTo(this.status,
                    typedOther.status);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetQueueName()).compareTo(
                typedOther.isSetQueueName());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetQueueName()) {
            lastComparison = TBaseHelper.compareTo(this.queueName,
                    typedOther.queueName);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        return 0;
    }

    @Override
    public MDAFields fieldForId(int fieldId) {
        return MDAFields.findByThriftId(fieldId);
    }

    @Override
    public void read(TProtocol iprot) throws TException {
        TField field;
        iprot.readStructBegin();
        while (true) {
            field = iprot.readFieldBegin();
            if (field.type == TType.STOP) {
                break;
            }
            switch (field.id) {
                case 1: // ID
                    if (field.type == TType.STRING) {
                        this.id = iprot.readString();
                    } else {
                        TProtocolUtil.skip(iprot, field.type);
                    }
                    break;
                case 2: // IP
                    if (field.type == TType.STRING) {
                        this.ip = iprot.readString();
                    } else {
                        TProtocolUtil.skip(iprot, field.type);
                    }
                    break;
                case 3: // CREATION_TIME
                    if (field.type == TType.I64) {
                        this.creationTime = iprot.readI64();
                        setCreationTimeIsSet(true);
                    } else {
                        TProtocolUtil.skip(iprot, field.type);
                    }
                    break;
                case 4: // ID_MACHINE
                    if (field.type == TType.STRING) {
                        this.idMachine = iprot.readString();
                    } else {
                        TProtocolUtil.skip(iprot, field.type);
                    }
                    break;
                case 5: // QUEUE_NAME
                    if (field.type == TType.STRING) {
                        this.queueName = iprot.readString();
                    } else {
                        TProtocolUtil.skip(iprot, field.type);
                    }
                    break;
                default:
                    TProtocolUtil.skip(iprot, field.type);
            }
            iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked
        // in the validate method
        validate();
    }

    @Override
    public void write(TProtocol oprot) throws TException {
        validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (this.id != null) {
            oprot.writeFieldBegin(ID_FIELD_DESC);
            oprot.writeString(this.id);
            oprot.writeFieldEnd();
        }
        if (this.ip != null) {
            oprot.writeFieldBegin(IP_FIELD_DESC);
            oprot.writeString(this.ip);
            oprot.writeFieldEnd();
        }
        oprot.writeFieldBegin(CREATION_TIME_FIELD_DESC);
        oprot.writeI64(this.creationTime);
        oprot.writeFieldEnd();
        if (this.idMachine != null) {
            oprot.writeFieldBegin(ID_MACHINE_FIELD_DESC);
            oprot.writeString(this.idMachine);
            oprot.writeFieldEnd();
        }
        if (this.queueName != null) {
            oprot.writeFieldBegin(QUEUE_NAME_FIELD_DESC);
            oprot.writeString(this.queueName);
            oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("MDA(");
        boolean first = true;

        sb.append("id:");
        if (this.id == null) {
            sb.append("null");
        } else {
            sb.append(this.id);
        }
        first = false;
        if (!first) {
            sb.append(", ");
        }
        sb.append("IP:");
        if (this.ip == null) {
            sb.append("null");
        } else {
            sb.append(this.ip);
        }
        first = false;
        if (!first) {
            sb.append(", ");
        }
        sb.append("creationTime:");
        sb.append(this.creationTime);
        first = false;
        if (!first) {
            sb.append(", ");
        }
        sb.append("idMachine:");
        if (this.idMachine == null) {
            sb.append("null");
        } else {
            sb.append(this.idMachine);
        }
        first = false;
        if (!first) {
            sb.append(", ");
        }
        sb.append("queueName:");
        if (this.queueName == null) {
            sb.append("null");
        } else {
            sb.append(this.queueName);
        }
        first = false;
        sb.append(")");
        return sb.toString();
    }

    public void validate() throws TException {
        // check for required fields
    }

    private void writeObject(ObjectOutputStream out) throws IOException {
        try {
            write(new TCompactProtocol(new TIOStreamTransport(out)));
        } catch (TException te) {
            throw new IOException(te);
        }
    }

    private void readObject(ObjectInputStream in) throws IOException,
            ClassNotFoundException {
        try {
            // it doesn't seem like you should have to do this, but java
            // serialization is wacky, and doesn't call the default constructor.
            __isset_bit_vector = new BitSet(1);
            read(new TCompactProtocol(new TIOStreamTransport(in)));
        } catch (TException te) {
            throw new IOException(te);
        }
    }
}
